/*
 * @# register.js 2011-12-16 上午11:20:18
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司 Guangzhou ianswer information
 * technology co. ltd.
 * 
 * All rights reserved!
 */

$(function() {

			$('#userCode').blur(function(e) {
						$(this).val($(this).val().toLowerCase());
			});

			var validator = $("#register-form").validate({
						onsubmit : false,
						rules : {
							'email' : {
								required : true,
								email : true,
								minlength : 8,
								maxlength : 25,
								unique : window.ctx + '/checkUserCode'
							},
							'nickname' : {
								required : true,
								minlength : 2,
								maxlength : 20
							},
							'password' : {
								required : true,
								minlength : 6,
								maxlength : 20
							},
							'confirmPwd' : {
								required : true,
								equalTo : '#password',
								minlength : 6,
								maxlength : 20
							}
						},
						messages : { // 出错提示信息
							'email' : {
								required : '请填写用户名！',
								email : "无效的用户名！",
								minlength : '用户名最小长度${0}位！',
								maxlength : "用户名最大长度${0}位！",
								unique : "帐号已存在！"
							},
							'nickname' : {
								required : "昵称不能为空！",
								minlength : '昵称最小长度${0}位！',
								maxlength : "昵称最大长度${0}位！"
							},
							'password' : {
								required : "密码不能为空！",
								minlength : "密码最小长度${0}位！",
								maxlength : "密码最大长度${0}位！"
							},
							'confirmPwd' : {
								required : "确认密码不能为空！",
								equalTo : "两次密码不一致！",
								minlength : "密码最小长度${0}位！",
								maxlength : "密码最大长度${0}位！"
							}
						},
						errorPlacement : $.handleError,
						success : $.handleSuccess,
						invalidHandler : $.invalidAlertHandler
					});

			$('#register-submit').click(function(e) {
					if (validator.form()) {
						$('#password').val(hex_md5($.trim($('#userPwd').val())));
						$('#confirmPwd').val(hex_md5($.trim($('#userPwd2').val())));
						$('#register-form').submit();
					}
			});
});